package top.dotgo.web.base.config.jackson;

import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;
import java.util.Date;

/**
 * @author : lin
 * @date : 2019/10/9 15:06
 */
@JacksonStdImpl
public class DateToStringSerializer extends StdSerializer<Date> {
    public static final DateToStringSerializer INSTANCE = new DateToStringSerializer();

    private DateToStringSerializer() {
        super(Date.class);
    }

    @Override
    public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeString(DateUtil.formatDateTime(date));
    }
}
